package cm309.BookingSystem.FM.web.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cm309.BookingSystem.common.Common;
import cm309.BookingSystem.common.MyConnection;
import cm309.BookingSystem.FM.factilites;;


public class ReadFMAction implements Action {
List<factilites> factilites=new ArrayList<factilites>();	
	
	@Override
	public void execute(HttpServletRequest request, HttpServletResponse response)   {
		MyConnection con=new MyConnection();
		try {
				
			ResultSet rs=con.getPS("select FACTILITESID ,FACTILITESINAME ,FACTILITESMEMBER ,MEMBERAGE " +
				           " ,CLASSIFICATION From BK_FM_MEMBER")
			               .executeQuery();
			
			factilites F=new factilites();
			factilites.clear();
			while (rs.next()) {
			F=new factilites();
			F.setFactilitesID(rs.getString("FACTILITESID"));
			cm309.BookingSystem.FM.factilites.setFactilitesName(rs.getString("FACTILITESNAME"));
			char[] cbuf=new char[1];
			rs.getCharacterStream("FactilitesGENDER").read(cbuf);
			F.setMemberAge(rs.getInt("MEMBERAGE"));
			F.setClassification(rs.getString("CLASSIFICATION"));
			
			factilites.add(F);
			
			}
			con.commit();
            con.PSclose();
			PrintWriter w = response.getWriter();
			
			w.println(Common.beanToJson(factilites));
			
			
		} catch (IOException e) {
			e.printStackTrace();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		finally {
		  con.close();
		}

	}

}
	


